/* 
 * File:   symtab.h
 * Author: abadalya
 *
 * Created on November 25, 2011, 4:19 PM
 */

#ifndef SYMTAB_H
#define	SYMTAB_H

struct expression;
struct lambda;

enum symbol_type {
    S_EXPRESSION,
    S_LAMBDA
};

struct symbol {
    enum symbol_type type;
    char* name;
    union _v {
        struct expression* expr;
        struct lambda* func;
    } value;
    struct symbol* link;
};

extern struct symbol* create_symbol(const char*);
extern struct symbol* create_expression_symbol(const char*, struct expression*);
extern struct symbol* create_lambda_symbol(const char*, struct lambda*);
extern void destroy_symbol(struct symbol*);

struct symbol_table {
    struct symbol* begin;
    struct symbol* end;
    int count;
};

extern struct symbol_table* create_symbol_table();
extern void insert_symbol(struct symbol_table*, struct symbol*);
extern struct symbol* search_symbol(struct symbol_table*, const char*);
extern struct symbol* take_symbol_at(struct symbol_table*, int);
extern void destroy_symbol_table(struct symbol_table*);
extern void print_table(struct symbol_table*);

#endif	/* SYMTAB_H */

